gcloud config set project project_id
gcloud ml-engine models list
pip install virtualenv
virtualenv -p python2 env_name
source env_name/bin/activate
gcloud init
pip install -U pip
pip install --upgrade tensorflow
gcloud auth application-default login
gcloud ml-engine models list
터미널에서 아래와 같이 입력해서 데이터를 받습니다
wget https://github.com/GoogleCloudPlatform/cloudml-samples/archive/master.zip
unzip master.zip
cd cloudml-samples-master/census/estimator
Cloud Machine Learning Engine : Training / Prediction
virtualenv --python=python env
source env/bin/activate
sudo pip install -r ../requirements.txt
sudo pip install haxor-news --upgrade --ignore-installed six
mkdir output
MODEL_DIR=output
rm -rf $MODEL_DIR/*
gcloud ml-engine local train \
--module-name trainer.task \
--package-path trainer/ \
-- \
--train-files $TRAIN_DATA \
--eval-files $EVAL_DATA \
--train-steps 1000 \
--job-dir $MODEL_DIR \
--eval-steps 100 \
--verbosity DEBUG
gcloud ml-engine local train \
--module-name trainer.task \
--package-path trainer/ \
--distributed \
-- \
--train-files $TRAIN_DATA \
--eval-files $EVAL_DATA \
--train-steps 1000 \
--job-dir $MODEL_DIR
ls -R output-dist/
python -m tensorflow.tensorboard --logdir=$MODEL_DIR
PROJECT_ID=$(gcloud config list project --format "value(core.project)")
AUTH_TOKEN=$(gcloud auth print-access-token)
SVC_ACCOUNT=$(curl -X GET -H "Content-Type: application/json" \
-H "Authorization: Bearer $AUTH_TOKEN" \
https://ml.googleapis.com/v1/projects/${PROJECT_ID}:getConfig \
| python -c "import json; import sys; response = json.load(sys.stdin); \
print response['serviceAccount']")
BUCKET_NAME="your_bucket_name"
gsutil -m defacl ch -u $SVC_ACCOUNT:R gs://$BUCKET_NAME
gsutil -m acl ch -u $SVC_ACCOUNT:R -r gs://$BUCKET_NAME
gsutil -m acl ch -u $SVC_ACCOUNT:W gs://$BUCKET_NAME
REGION=asia-east1
echo $BUCKET_NAME
gsutil cp -r data gs://$BUCKET_NAME/data
TRAIN_DATA=gs://$BUCKET_NAME/data/adult.data.csv
EVAL_DATA=gs://$BUCKET_NAME/data/adult.test.csv
gsutil cp ../test.json gs://$BUCKET_NAME/data/test.json
TEST_JSON=gs://$BUCKET_NAME/data/test.json
JOB_NAME=census_single_1
OUTPUT_PATH=gs://$BUCKET_NAME/$JOB_NAME
gcloud ml-engine jobs submit training $JOB_NAME \
--job-dir $OUTPUT_PATH \
--runtime-version 1.2 \
--module-name trainer.task \
--package-path trainer/ \
--region $REGION \
-- \
--train-files $TRAIN_DATA \
--eval-files $EVAL_DATA \
--train-steps 1000 \
--verbosity DEBUG
gcloud ml-engine jobs submit training $JOB_NAME \
--job-dir $OUTPUT_PATH \
--runtime-version 1.2 \
--module-name trainer.task \
--package-path trainer/ \
--region $REGION \
--scale-tier STANDARD_1 \
-- \
--train-files $TRAIN_DATA \
--eval-files $EVAL_DATA \
--train-steps 1000 \
--verbosity DEBUG \
--eval-steps 100
하이퍼 파라미터 설정 파일 (yaml 파일)이 존재해야 합니다
census의 예시 파일
trainingInput:
hyperparameters:
goal: MAXIMIZE
hyperparameterMetricTag: accuracy
maxTrials: 4
maxParallelTrials: 2
params:
- parameterName: first-layer-size
type: INTEGER
minValue: 50
maxValue: 500
scaleType: UNIT_LINEAR_SCALE
- parameterName: num-layers
type: INTEGER
minValue: 1
maxValue: 15
scaleType: UNIT_LINEAR_SCALE
- parameterName: scale-factor
type: DOUBLE
minValue: 0.1
maxValue: 1.0
scaleType: UNIT_REVERSE_LOG_SCALE
HPTUNING_CONFIG=../hptuning_config.yaml
JOB_NAME=census_core_hptune_1
TRAIN_DATA=gs://$BUCKET_NAME/data/adult.data.csv
EVAL_DATA=gs://$BUCKET_NAME/data/adult.test.csv
OUTPUT_PATH=gs://$BUCKET_NAME/$JOB_NAME
gcloud ml-engine jobs submit training $JOB_NAME \
--stream-logs \
--job-dir $OUTPUT_PATH \
--runtime-version 1.2 \
--config $HPTUNING_CONFIG \
--module-name trainer.task \
--package-path trainer/ \
--region $REGION \
--scale-tier STANDARD_1 \
-- \
--train-files $TRAIN_DATA \
--eval-files $EVAL_DATA \
--train-steps 1000 \
--verbosity DEBUG \
--eval-steps 100
In [ ]: